package com.atmilan.quartz.utils;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
import java.util.UUID;

import javax.imageio.ImageIO;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.atmilan.quartz.model.entity.crmeb.StoreProduct;
import com.atmilan.quartz.model.entity.crmeb.StoreProductDescription;
import com.atmilan.quartz.service.IStoreProductDescriptionService;
import com.atmilan.quartz.service.IStoreProductService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.annotation.JsonValue;
import com.github.pagehelper.util.StringUtil;

import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;

/**
 * 阿里云 - 对象存储OSS工具
 */
@Slf4j
@Service
public class OSSUtil {
    private volatile static OSSClient instance;
    @Autowired
    IStoreProductService storeProductService;
    @Autowired
    private IStoreProductDescriptionService storeProductDescriptionService;
    @Autowired
    RestTemplateUtil restTemplateUtil;

    private OSSUtil() {
    }

    /**
     * 单例
     * @return  OSS工具类实例
     */
    private static OSSClient getOSSClient() {
        if (instance == null) {
            synchronized (OSSUtil.class) {
                if (instance == null) {
                    //log.warn("阿里云 - 对象存储OSS - 认证信息: endPoint:{} and accessKeyId:{} and accessKeySecret:{}", AliyunConfig.getEndPoint(), AliyunConfig.getAccessKeyId(), AliyunConfig.getAccessKeySecret());
                    instance = new OSSClient(AliyunConfig.getEndPoint(), AliyunConfig.getAccessKeyId(), AliyunConfig.getAccessKeySecret());
                }
            }
        }
        return instance;
    }

    //设置URL过期时间为100年
    private final static Date OSS_URL_EXPIRATION = DateUtils.addDays(new Date(), 365 * 100);

    //文件路径的枚举
    public enum FileDirType {
        RUIJU("ruiju");
        private final String dir;

        FileDirType(String dir) {
            this.dir = dir;
        }

        @JsonValue
        public String getDir() {
            return dir;
        }
    }

    /**
     * 上传文件---去除URL中的？后的时间戳
     * @param file 文件
     * @param fileDir 上传到OSS上文件的路径
     * @return 文件的访问地址
     * @throws Exception 
     */
    public static String upload(MultipartFile file, FileDirType fileDir) {
        OSSUtil.createBucket();
        String fileName = OSSUtil.uploadFile(file, fileDir);
        String fileOssURL = OSSUtil.getImgUrl(fileName, fileDir);
        int firstChar = fileOssURL.indexOf("?");
        if (firstChar > 0) {
            fileOssURL = fileOssURL.substring(0, firstChar);
        }
        return fileOssURL;
    }

    /**
     * 上传来源网络的图片
     * @param sourceImgUrl
     * @return
     * @throws Exception
     */
    public static String uploadFile(byte[] bytes, String sourceImgUrl, String newImgName, String barCode) throws Exception {
        String fileOssURL = "";
        if (null == bytes) {
            //log.info("--------------- 商品: {}, 没获取到图片流 ---------------", barCode);
            return sourceImgUrl;
        }
        try {
            if (StringUtils.isEmpty(sourceImgUrl) || StringUtils.isEmpty(newImgName)) {
                log.info("--------------- 商品: {}, 没获取到图片地址 ---------------", barCode);
                return sourceImgUrl;
            }

            fileOssURL = OSSUtil.aliYunUploadFile(bytes, newImgName);

        } catch (Exception e) {
            log.info("--------------- 商品: {}, 上传OSS异常 ---------------", barCode, e);
        } finally {
            //若阿里云链接替换失效，返回原链接
            if (StringUtils.isEmpty(fileOssURL)) {
                return sourceImgUrl;
            }
        }

        return fileOssURL;
    }

    /**
     * 获取上传图片新名称
     * @param sourceImgUrl
     * @param barCode
     * @return
     * @throws Exception
     */
    public static String uploadFileName(String sourceImgUrl, String barCode) {

        String newImgName = "";
        String suffixName = "";

        //Buyer
        int buyerFlag = sourceImgUrl.indexOf("http://buyer-app-img.cmsok.com");
        if (-1 != buyerFlag) {
            int buyerEndChar = sourceImgUrl.lastIndexOf("?");
            int firstChar = sourceImgUrl.lastIndexOf(".");
            suffixName = sourceImgUrl.substring(firstChar, buyerEndChar);
        }

        //Europe
        int europeFlag = sourceImgUrl.indexOf("http://imagestudio69.atelier98.net");
        if (-1 != europeFlag) {
            int europeEndChar = sourceImgUrl.lastIndexOf(".");
            suffixName = sourceImgUrl.substring(europeEndChar);
        }

        newImgName = barCode + suffixName;

        return newImgName;
    }

    /**
     * 图片尺寸处理
     */
    private static InputStream imageDizeDeal(InputStream inputStream) throws IOException {

        //图片尺寸调整，用于以图搜图
        int imgMinWidth = 128;
        int imgMinHeight = 128;

        int imgMaxWidth = 1024;
        int imgMaxHeight = 1024;

        //字节流转图片对象
        BufferedImage bufImg = ImageIO.read(inputStream);
        if (!(bufImg.getWidth() > imgMinWidth && bufImg.getHeight() > imgMinHeight && bufImg.getWidth() < imgMaxWidth && bufImg.getHeight() < imgMaxHeight)) {
            // 存储图片文件byte数组
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            //防止图片变红
            BufferedImage newBufferedImage = new BufferedImage(imgMaxWidth, imgMaxHeight, BufferedImage.TYPE_INT_RGB);
            newBufferedImage.createGraphics().drawImage(bufImg, 0, 0, Color.WHITE, null);
            //先转成jpg格式来压缩,然后在通过OSS来修改成源文件本来的后缀格式
            ImageIO.write(newBufferedImage, "jpg", bos);
            //获取输出流
            inputStream = new ByteArrayInputStream(bos.toByteArray());
        }
        return inputStream;
    }

    /**
         * 当Bucket不存在时创建Bucket
         *
         * @throws OSSException 异常
         * Bucket命名规则：
         *  1.只能包含小写字母、数字和短横线，
         *  2.必须以小写字母和数字开头和结尾
         *  3.长度在3-63之间
         */
    private static void createBucket() {
        try {
            if (!OSSUtil.getOSSClient().doesBucketExist(AliyunConfig.getBucketName())) {//判断是否存在该Bucket，不存在时再重新创建
                OSSUtil.getOSSClient().createBucket(AliyunConfig.getBucketName());
            }
        } catch (Exception e) {
            //  logger.error("{}", "创建Bucket失败,请核对Bucket名称(规则：只能包含小写字母、数字和短横线，必须以小写字母和数字开头和结尾，长度在3-63之间)");
            //  throw new OSSCreateBucketRuntimeException("创建Bucket失败,请核对Bucket名称(规则：只能包含小写字母、数字和短横线，必须以小写字母和数字开头和结尾，长度在3-63之间)");
            System.out.println("创建Bucket失败,请核对Bucket名称(规则：只能包含小写字母、数字和短横线，必须以小写字母和数字开头和结尾，长度在3-63之间)");
        }
    }

    /**
     * 上传到OSS服务器  如果同名文件会覆盖服务器上的
     * @param file 文件
     * @param fileDir  上传到OSS上文件的路径
     * @return 文件的访问地址
     * @throws Exception 
     */
    private static String uploadFile(MultipartFile file, FileDirType fileDir) {
        String fileName = String.format("%s.%s", UUID.randomUUID().toString(), FilenameUtils.getExtension(file.getOriginalFilename()));

        try (InputStream inputStream = file.getInputStream()) {
            //创建上传Object的Metadata
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(inputStream.available());
            objectMetadata.setCacheControl("no-cache");
            objectMetadata.setHeader("Pragma", "no-cache");
            objectMetadata.setContentType(getContentType(FilenameUtils.getExtension("." + file.getOriginalFilename())));
            objectMetadata.setContentDisposition("inline;filename=" + fileName);
            //上传文件
            String oldName = file.getOriginalFilename();
            //获取后缀名
            String imgType = oldName.substring(oldName.lastIndexOf("."));
            //拼接新的文件名
            String newName = fileName + imgType;
            PutObjectResult putResult = OSSUtil.getOSSClient().putObject(AliyunConfig.getBucketName(), fileDir.getDir() + newName, inputStream, objectMetadata);
            return fileName;
        } catch (Exception e) {
            //logger.error("{}", "上传文件失败");
            //   throw new OssPutObjectRuntimeException("上传文件失败");
            e.printStackTrace();
        }
        return null;
    }

    /**
     * AliYun OSS 上传接口
     *
     * @param byteArrayFile
     * @param fileName
     * @return
     */
    public static String aliYunUploadFile(byte[] byteArrayFile, String fileName) {

        if (StringUtils.isEmpty(fileName)) {
            return "";
        }

        try {
            OSSClient ossClient = OSSUtil.getOSSClient();
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            //图片压缩
            //compressImage(flag, byteArrayFile, out);

            //            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(out.toByteArray());
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayFile);

            //容器不存在，就创建
            if (!ossClient.doesBucketExist(AliyunConfig.getBucketName())) {
                ossClient.createBucket(AliyunConfig.getBucketName());
                CreateBucketRequest createBucketRequest = new CreateBucketRequest(AliyunConfig.getBucketName());
                createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
                ossClient.createBucket(createBucketRequest);
            }
            //创建文件路径
            String key = AliyunConfig.getFilePath() + fileName;
            //log.warn("阿里云 - 对象存储OSS - 上传图片 - 传入参数: bucketName:{} and key:{}", AliyunConfig.getBucketName(), key);
            //上传文件
            PutObjectResult result = ossClient.putObject(new PutObjectRequest(AliyunConfig.getBucketName(), key, byteArrayInputStream));
            //设置权限 这里是公开读
            ossClient.setBucketAcl(AliyunConfig.getBucketName(), CannedAccessControlList.PublicRead);

            String fileOssURL = AliyunConfig.getOssUrl() + key;

            //			log.warn("阿里云 - 对象存储OSS - 上传图片 - 返回结果: fileName:{}, fileOssURL:{}, result:{}", fileName, fileOssURL, result);

            if (null != result) {
                return fileOssURL;
            }

        } catch (OSSException e) {
            //			log.error("阿里云 - 对象存储OSS - 上传图片 - 失败", e);
        }

        return "";
    }

    /**
     * 图片压缩
     * @param byteArrayFile
     * @param flag
     * @return
     */
    private static void compressImage(boolean flag, byte[] byteArrayFile, ByteArrayOutputStream out) {

        try {
            InputStream buffin = new ByteArrayInputStream(byteArrayFile, 0, byteArrayFile.length);

            if (flag) {
                //保持纵横比，质量降低为原来的42%
                Thumbnails.of(buffin).scale(1.00f).outputQuality(0.42f).toOutputStream(out);
            } else {
                //图片尺寸 200 * 300
                ByteArrayInputStream in = new ByteArrayInputStream(byteArrayFile);
                BufferedImage bim = ImageIO.read(in);
                int imgWidth = bim.getWidth();
                int imgHeight = bim.getHeight();
                Thumbnails.of(buffin).size((int) (imgWidth * 0.5), (int) (imgHeight * 0.5)).toOutputStream(out);
            }
        } catch (Exception e) {
            log.error("阿里云 - 对象存储OSS - 图片压缩 - 失败", e);
        }
    }

    public static byte[] input2byte(InputStream inStream) throws IOException {
        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        int rc = 0;
        while ((rc = inStream.read(buff, 0, 100)) > 0) {
            swapStream.write(buff, 0, rc);
        }
        byte[] in2b = swapStream.toByteArray();
        return in2b;
    }

    /**
     * 本地图片文件上传到OSS服务器
     * 如果同名文件会覆盖服务器上的
     * @param file 文件
     * @return 文件的访问地址
     * @throws Exception
     */
    public static String uploadLocalImage(String filePath, MultipartFile file, String fullName) throws Exception {

        String imageUrl = null;

        //获取图片类型
        String imageType = getImageType(FilenameUtils.getExtension("." + file.getOriginalFilename()));

        if (StringUtils.isEmpty(imageType)) {
            throw new Exception("图片格式不合法，必须为JPG、JPEG、PNG");
        }

        try {
            InputStream inputStream = file.getInputStream();

            //图片尺寸处理, 有点问题 上传图片失效
            //inputStream = imageDizeDeal(inputStream);

            //创建上传Object的Metadata
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(inputStream.available());
            objectMetadata.setCacheControl("no-cache");
            objectMetadata.setHeader("Pragma", "no-cache");
            objectMetadata.setContentType(imageType);
            objectMetadata.setContentDisposition("inline;filename=" + fullName);
            //创建文件路径
            String key = filePath + fullName;
            //String key = "userSearchImage/" + fullName;
            PutObjectResult putResult = OSSUtil.getOSSClient().putObject(AliyunConfig.getBucketName(), key, inputStream, objectMetadata);
            if (null != putResult) {
                imageUrl = AliyunConfig.getOssUrl() + key;
            }

        } catch (Exception e) {
            //			log.error("阿里云 - 对象存储OSS - 上传图片 - 失败:"+ e.getMessage(), e);
            throw new Exception("搜图失败");
        }

        return imageUrl;
    }

    public static String getLocalFileName(MultipartFile file, String fileName) throws Exception {

        //文件格式后缀
        String fileSuffix = FilenameUtils.getExtension(file.getOriginalFilename());

        //拼接文件全名称
        return String.format("%s.%s", fileName, fileSuffix);
    }

    private static String getImgUrl(String fileUrl) {
        if (StringUtils.isEmpty(fileUrl)) {
            throw new RuntimeException("文件地址为空");
        }
        //获取oss图片URL失败
        URL url = OSSUtil.getOSSClient().generatePresignedUrl(AliyunConfig.getBucketName(), fileUrl, OSS_URL_EXPIRATION);
        if (url == null) {
            log.error("商品图片上传到阿里云OSS服务器 - 获取oss文件URL失败");
        }
        return url.toString();
    }

    /**
     * 获得文件路径
     * @param fileUrl  文件的URL
     * @param fileDir  文件在OSS上的路径
     * @return 文件的路径
     */
    private static String getImgUrl(String fileUrl, FileDirType fileDir) {
        if (StringUtils.isEmpty(fileUrl)) {
            //   logger.error("{}", "文件地址为空");
            throw new RuntimeException("文件地址为空");
        }
        String[] split = fileUrl.split("/");

        //获取oss图片URL失败
        URL url = OSSUtil.getOSSClient().generatePresignedUrl(AliyunConfig.getBucketName(), fileDir.getDir() + split[split.length - 1], OSS_URL_EXPIRATION);
        if (url == null) {
            //     logger.error("{}", "获取oss文件URL失败");
            //    throw new OSSGeneratePresignedUrlRuntimeException("获取oss文件URL失败");
            System.err.println("获取oss文件URL失败");
        }
        return url.toString();
    }

    /**
     * 判断OSS服务文件上传时图片
     * 图片格式：JPG、JPEG、PNG
     *
     * @param FilenameExtension 文件后缀
     * @return 后缀
     */
    private static String getImageType(String FilenameExtension) {
        if (FilenameExtension.equalsIgnoreCase("jpeg") || FilenameExtension.equalsIgnoreCase("jpg") || FilenameExtension.equalsIgnoreCase("png")) {
            return "image/jpg";
        }

        return "";
    }

    /**
     * 判断OSS服务文件上传时文件的contentType
     *
     * @param FilenameExtension 文件后缀
     * @return 后缀
     */
    private static String getContentType(String FilenameExtension) {
        if (FilenameExtension.equalsIgnoreCase("bmp")) {
            return "image/bmp";
        }
        if (FilenameExtension.equalsIgnoreCase("gif")) {
            return "image/gif";
        }
        if (FilenameExtension.equalsIgnoreCase("jpeg") || FilenameExtension.equalsIgnoreCase("jpg") || FilenameExtension.equalsIgnoreCase("png")) {
            return "image/jpeg";
        }
        if (FilenameExtension.equalsIgnoreCase("html")) {
            return "text/html";
        }
        if (FilenameExtension.equalsIgnoreCase("txt")) {
            return "text/plain";
        }
        if (FilenameExtension.equalsIgnoreCase("vsd")) {
            return "application/vnd.visio";
        }
        if (FilenameExtension.equalsIgnoreCase("pptx") || FilenameExtension.equalsIgnoreCase("ppt")) {
            return "application/vnd.ms-powerpoint";
        }
        if (FilenameExtension.equalsIgnoreCase("docx") || FilenameExtension.equalsIgnoreCase("doc")) {
            return "application/msword";
        }
        if (FilenameExtension.equalsIgnoreCase("xml")) {
            return "text/xml";
        }

        /**
         * 下面是对视频文件的处理
         */
        if (FilenameExtension.equalsIgnoreCase("mp4")) {
            return "video/mpeg4";
        }

        if (FilenameExtension.equalsIgnoreCase("rmvb")) {
            return "application/vnd.rn-realmedia-vbr";
        }

        if (FilenameExtension.equalsIgnoreCase("wmv")) {
            return "video/x-ms-wmv";
        }

        if (FilenameExtension.equalsIgnoreCase("avi")) {
            return "video/avi";
        }

        if (FilenameExtension.equalsIgnoreCase("avi")) {
            return "video/avi";
        }

        if (FilenameExtension.equalsIgnoreCase("wav")) {
            return "audio/wav";
        }

        return "image/jpeg";
    }

    /**
     * 删除OSS图片
     *
     * 如需删除文件夹，请将ObjectName设置为对应的文件夹名称。
     * 如果文件夹非空，则需要将文件夹下的所有object删除后才能删除该文件夹。
     * @return
     * @throws Exception
     */
    public static void deleteFile(String filePath, String fileName) throws Exception {
        try {
            OSSClient ossClient = OSSUtil.getOSSClient();
            String key = filePath + fileName;
            ossClient.deleteObject(AliyunConfig.getBucketName(), key);
        } catch (Exception e) {
            log.error("阿里云 - 对象存储OSS - 删除图片 - 失败", e);
        }
        //log.warn("阿里云 - 对象存储OSS - 删除图片 - 成功, fileName:{} ", fileName);
    }

    public static void deleteLocalFile(String filePath, String fileName) throws Exception {
        try {
            OSSClient ossClient = OSSUtil.getOSSClient();
            String key = filePath + fileName;
            ossClient.deleteObject(AliyunConfig.getBucketName(), key);
        } catch (Exception e) {
            log.error("阿里云 - 对象存储OSS - 删除图片 - 失败", e);
        }
        log.warn("阿里云 - 对象存储OSS - 删除图片 - 成功, fileName:{} ", fileName);
    }

    /**
     * 判断OSS图片是否存在
     *
     * @return
     * @throws Exception
     */
    public static boolean selectFile(String fileName) throws Exception {
        OSSClient ossClient = OSSUtil.getOSSClient();
        if (StringUtils.isNotEmpty(fileName)) {
            OSSObject obj = ossClient.getObject(AliyunConfig.getBucketName(), fileName);
            return null != obj;
        }
        return false;
    }

    public void sliderImageOssURL(StoreProductDescription description) {
        try {
            String imageUrl = description.getImage();
            imageUrl = imageUrl.replaceAll(" ", "%20");
            
            StoreProduct storeProduct = storeProductService.getById(description.getProductId());
            String sliderImageUrl = description.getSliderImage();
            // 根路径
            String rootPath = "buyer/" + storeProduct.getIsEurope() + "/" + storeProduct.getId() + "/";

            // 主图处理
            String isJpg = "";
            if (-1 != imageUrl.indexOf(".jpg")) {
                isJpg = ".jpg";
            } else if (-1 != imageUrl.indexOf(".JPG")) {
                isJpg = ".JPG";
            } else if (-1 != imageUrl.indexOf(".jpeg")) {
                isJpg = ".jpeg";
            } else if (-1 != imageUrl.indexOf(".gif")) {
                isJpg = ".gif";
            } else if (-1 != imageUrl.indexOf(".png")) {
                isJpg = ".png";
            } else {
            	isJpg = ".png";
            }
            
            if (!StringUtil.isEmpty(imageUrl) && StringUtil.isNotEmpty(isJpg)) {
                // 获取图片字节流
                byte[] bytes = restTemplateUtil.getBytes(imageUrl);
                // 组合新图片名称
                int length = -1 == imageUrl.lastIndexOf(isJpg) ? imageUrl.length() : imageUrl.lastIndexOf(isJpg);
                String imageSubUrl = imageUrl.substring(0, length);
                int z = imageSubUrl.lastIndexOf("/");
                String imgName = imageSubUrl.substring(z + 1, imageSubUrl.length()).replaceAll("\\?", "").replaceAll("=", "").replaceAll("&", "");
                String ossName = (rootPath + imgName + isJpg).replaceAll("'", "");

                // 上传到OSS, 失败则返回原地址
                String imageOssURL = OSSUtil.uploadFile(bytes, imageUrl, ossName, storeProduct.getBarCode());
                description.setImage(imageOssURL);
            }

            // 轮播图处理
            JSONArray sliderUrlList = new JSONArray();
            if (StringUtils.isNotEmpty(sliderImageUrl)) {
                JSONArray sliderImageUrlArr = JSON.parseArray(sliderImageUrl);
                //上传图片
                for (int i = 0; i < sliderImageUrlArr.size(); i++) {
                    String sliderUrl = sliderImageUrlArr.getString(i);
                    String isSliderJpg = "";
                    if (-1 != sliderUrl.indexOf("jpg")) {
                        isSliderJpg = ".jpg";
                    } else if (-1 != sliderUrl.indexOf("JPG")) {
                        isSliderJpg = ".JPG";
                    } else if (-1 != sliderUrl.indexOf("jpeg")) {
                        isSliderJpg = ".jpeg";
                    } else if (-1 != sliderUrl.indexOf("gif")) {
                        isSliderJpg = ".gif";
                    } else if (-1 != sliderUrl.indexOf("png")) {
                        isSliderJpg = ".png";
                    } else {
                        isSliderJpg = ".png";
                    }
                    if (!StringUtil.isEmpty(sliderUrl) && StringUtil.isNotEmpty(isSliderJpg)) {
                        // 获取图片字节流
                        byte[] bytes = restTemplateUtil.getBytes(sliderUrl);
                        // 组合新图片名称
                        int length = -1 == sliderUrl.lastIndexOf(isSliderJpg) ? sliderUrl.length() : sliderUrl.lastIndexOf(isSliderJpg);
                        String imageSubUrl = sliderUrl.substring(0, length);
                        int z = imageSubUrl.lastIndexOf("/");
                        String imgName = imageSubUrl.substring(z + 1, imageSubUrl.length()).replaceAll("\\?", "").replaceAll("=", "").replaceAll("&", "");
                        String ossName = (rootPath + imgName + isSliderJpg).replaceAll("'", "");

                        // 上传到OSS, 失败则返回原地址
                        sliderUrl = OSSUtil.uploadFile(bytes, imageUrl, ossName, storeProduct.getBarCode());
                    }

                    sliderUrlList.add(sliderUrl);
                }
            }
            // 更新轮播图
            storeProductDescriptionService.update(Wrappers.<StoreProductDescription>lambdaUpdate()
            		.eq(StoreProductDescription :: getProductId, storeProduct.getId())
            		.set(StoreProductDescription :: getImage, description.getImage())
            		.set(StringUtils.isNotEmpty(sliderImageUrl), StoreProductDescription :: getSliderImage, sliderUrlList.toJSONString())
            		);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
}
